cmake_minimum_required(VERSION 3.16)

project(cpp2ftl LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

add_executable(${PROJECT_NAME}
  main.cpp
)
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core)

set(now_output_dir ${CMAKE_CURRENT_LIST_DIR}/../../fmpp)
get_filename_component(now_output_dir_abs ${now_output_dir} ABSOLUTE)

# PRE_BUILD	在目标中执行任何其他规则之前运行
# PRE_LINK	在编译源代码之后，链接二进制文件或库文件之前运行
# POST_BUILD 在目标内所有其他规则均已执行后运行
# 定义运行后脚本命令
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PROJECT_NAME}.exe ${now_output_dir_abs}/
  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PROJECT_NAME}.ilk ${now_output_dir_abs}/
  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PROJECT_NAME}.pdb ${now_output_dir_abs}/
)

include(GNUInstallDirs)

install(TARGETS ${PROJECT_NAME}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)